/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package epollclient;

import java.io.IOException;
import java.net.InetAddress;
import java.nio.channels.Selector;
import java.nio.channels.spi.SelectorProvider;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Bryce
 */
public class ClientManager implements Runnable{
    private int numClients;
    private int serverPort;
    private InetAddress serverAddress;
    private Selector selector;
    
    public ClientManager(int clientsPerThread, int port, InetAddress address) throws IOException {
        this.numClients = clientsPerThread;
        this.serverPort = port;
        this.serverAddress = address;
        this.selector = SelectorProvider.provider().openSelector();
    }

    @Override
    public void run() {
        //Create multiple client connections
        for (int i = 0; i < numClients; i++) {
            try {
                EPollClient client = new EPollClient(serverAddress, serverPort,selector);
                Thread t = new Thread(client);
                t.setDaemon(true);
                t.start();
                RspHandler handler = new RspHandler();
                client.send("Test Data!!!".getBytes(), handler);
                handler.waitForResponse();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
}
